<template>
  <div :class="['breadcrumb-box mask-image', !useGlobal.globalConfig.breadcrumbIcon && 'no-icon']">
    <el-breadcrumb :separator-icon="ArrowRight">
      <transition-group name="breadcrumb">
        <el-breadcrumb-item v-for="item in breadcrumbList" :key="item.path">
          <div class="el-breadcrumb__inner is-link">
            <el-icon v-show="item.meta.icon && useGlobal.globalConfig.breadcrumbIcon" class="breadcrumb-icon">
              <Icon :icon="item.meta.icon" />
            </el-icon>
            <span class="breadcrumb-title">{{ item.meta.title }}</span>
          </div>
        </el-breadcrumb-item>
      </transition-group>
    </el-breadcrumb>
  </div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import { useRoute } from "vue-router";
import { ArrowRight } from "@element-plus/icons-vue";
import { useAuthStore, useGlobalStore } from "@/stores";

defineOptions({
  name: "Breadcrumb"
});

const route = useRoute();
const useAuth = useAuthStore();
const useGlobal = useGlobalStore();

const breadcrumbList = computed(() => {
  const breadcrumbResult = useAuth.breadcrumbListGet();
  const breadcrumbData = breadcrumbResult[route.matched[route.matched.length - 1].path] ?? [];
  // 面包屑前面需要加【基础路径/】则取消下面注释,然后看面包屑变化
  // if (breadcrumbData[0]?.path !== "/") {
  //   breadcrumbData = [{ path: "/", meta: { icon: "gongzuotai", title: "首页" } }, ...breadcrumbData];
  // }
  return breadcrumbData;
});
</script>

<style scoped lang="scss">
.breadcrumb-box {
  display: flex;
  align-items: center;
  overflow: hidden;
  .el-breadcrumb {
    white-space: nowrap;
    .el-breadcrumb__item {
      position: relative;
      display: inline-block;
      float: none;
      .el-breadcrumb__inner {
        display: inline-flex;
        &.is-link {
          color: var(--el-header-text-color);
          &:hover {
            color: var(--el-color-primary);
          }
        }
        .breadcrumb-icon {
          margin-top: 2px;
          margin-right: 6px;
          font-size: 16px;
        }
        .breadcrumb-title {
          margin-top: 3px;
        }
      }
      &:last-child .el-breadcrumb__inner,
      &:last-child .el-breadcrumb__inner:hover {
        color: var(--el-header-text-color-regular);
      }
      :deep(.el-breadcrumb__separator) {
        position: relative;
        top: -1px;
      }
    }
  }
}
.no-icon {
  .el-breadcrumb {
    .el-breadcrumb__item {
      top: -2px;
      :deep(.el-breadcrumb__separator) {
        top: 2px;
      }
    }
  }
}
</style>
